package com.watermark.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import lombok.Data;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Data
@Configuration
@ConfigurationProperties(prefix = "app")
public class AppConfig implements WebMvcConfigurer {
    private Upload upload = new Upload();
    private Watermark watermark = new Watermark();

    @Data
    public static class Upload {
        private String dir = "uploads";
    }

    @Data
    public static class Watermark {
        private int minSize = 32;
        private int maxSize = 2048;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置外部文件访问
        registry.addResourceHandler("/uploads/**")
                .addResourceLocations("file:" + upload.getDir() + "/");
    }
} 